package com.example.permissionsystem1_1.businessFunction.service.converter;

import com.example.permissionsystem1_1.businessFunction.dao.entity.po.RoleFunctionPo;
import com.example.permissionsystem1_1.businessFunction.dao.entity.po.UserRolePo;
import com.example.permissionsystem1_1.businessFunction.service.entity.reqModel.roleFunctionReqModel.RoleFunctionSelectAllFunctionsByRoleIdReqModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.reqModel.roleFunctionReqModel.RoleFunctionSetRoleFunctionRelationReqModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.reqModel.userRoleReqModel.UserRoleSelectAllRolesByUserIdReqModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.reqModel.userRoleReqModel.UserRoleSetUserRoleRelationReqModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.rspModel.roleFunctionRspModel.RoleFunctionRspModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.rspModel.roleFunctionRspModel.RoleFunctionSelectAllFunctionsByRoleIdRspModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.rspModel.roleFunctionRspModel.RoleFunctionSetRoleFunctionRelationRspModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.rspModel.userRoleRspModel.UserRoleRspModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.rspModel.userRoleRspModel.UserRoleSelectAllRolesByUserIdRspModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.rspModel.userRoleRspModel.UserRoleSetUserRoleRelationRspModel;
import com.example.permissionsystem1_1.common.businessFunction.BaseServiceConverter;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

public class RoleFunctionServiceConverter extends BaseServiceConverter {
    //1.selectAllFunctionsByUserId
    public static RoleFunctionPo convertReqModelToPo(RoleFunctionSelectAllFunctionsByRoleIdReqModel reqModel) {
        if (reqModel == null || reqModel.getRoleId()==null) {
            return null;
        }
        RoleFunctionPo po=new RoleFunctionPo();
        BeanUtils.copyProperties(reqModel, po);
        return po;
    }
    public static RoleFunctionSelectAllFunctionsByRoleIdRspModel covertToSelectAllRolesByRoleIdModel(List<RoleFunctionPo> pos) {
        if( pos == null) {
            return null;
        }
        RoleFunctionSelectAllFunctionsByRoleIdRspModel rspModel=new RoleFunctionSelectAllFunctionsByRoleIdRspModel();
        if(pos.size()>0){
            List<RoleFunctionRspModel> roleFunctionRspModels=new ArrayList<>();
            for (RoleFunctionPo po:pos) {
                RoleFunctionRspModel roleFunctionRspModel=new RoleFunctionRspModel();
                BeanUtils.copyProperties(po, roleFunctionRspModel);
                roleFunctionRspModels.add(roleFunctionRspModel);
            }
            rspModel.setRoleFunctionRspModels(roleFunctionRspModels);
        }
        return rspModel;
    }
    //2.setRoleFunctionRelation
    public static List<RoleFunctionPo> convertReqModelToPo(RoleFunctionSetRoleFunctionRelationReqModel reqModel) {
        if (reqModel == null || reqModel.getRoleId()==null || reqModel.getFunctionIds()==null || reqModel.getFunctionIds().size()<=0) {
            return null;
        }
        List<Long> functionIds=reqModel.getFunctionIds();
        List<RoleFunctionPo> roleFunctionPos=new ArrayList<>();
        for (Long functionId:functionIds) {
            RoleFunctionPo roleFunctionPo=new RoleFunctionPo();
            roleFunctionPo.setRoleId(reqModel.getRoleId());
            roleFunctionPo.setFunctionId(functionId);
            setDefaultAttributesValue(roleFunctionPo);
            roleFunctionPos.add(roleFunctionPo);
        }
        return roleFunctionPos;
    }
    public static RoleFunctionSetRoleFunctionRelationRspModel covertToSetRoleFunctionRelationModel(Integer i) {
        RoleFunctionSetRoleFunctionRelationRspModel rspModel=new RoleFunctionSetRoleFunctionRelationRspModel();
        rspModel.setResultSum(i);
        return rspModel;
    }




}
